import threading
from time import ctime, sleep

loops = (4, 2)  # 元组


class MyThread(threading.Thread):
    def __init__(self, target, args):
        super().__init__()
        self.target = target
        self.args = args

    def run(self):
        self.target(*self.args)


def loop(nloop, nsec):
    print(ctime(), "start loop", nloop)
    sleep(nsec)
    print(ctime(), "end loop", nloop)


if __name__ == "__main__":
    threads = []
    nloops = range(len(loops))
    for i in nloops:
        t = MyThread(loop, (i, loops[i]))
        threads.append(t)
    for i in nloops:
        threads[i].start()  # 启动线程运行
    for i in nloops:
        threads[i].join()
    print("-----MainThread-----")
